package com.example.attrimirror.model;

import java.util.ArrayList;
import java.util.List;

public class Attribute {
    private String id;
    private String name;
    private String description;
    private int level;      // 当前等级
    private double experience;  // 改为 double 类型
    private boolean isPositive;  // 新增字段，标记是否为正面属性
    private List<Long> nailTimestamps;  // 存储钉子的时间戳列表

    public Attribute() {
        this.level = 0;
        this.experience = 0;
        this.nailTimestamps = new ArrayList<>();
    }

    // Getters and setters
    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public int getLevel() {
        return level;
    }

    public void setLevel(int level) {
        this.level = level;
    }

    public double getExperience() {
        return experience;
    }

    public void setExperience(double experience) {
        this.experience = experience;
    }

    public boolean isPositive() { return isPositive; }
    public void setPositive(boolean positive) { isPositive = positive; }

    // 计算升级所需经验
    public int getRequiredExperience() {
        return (int)(2.5 * (level + 1) * (level + 2));
    }

    // 获取当前等级的经验进度（0-100）
    public int getProgress() {
        int required = getRequiredExperience();
        return required > 0 ? (int)((experience * 100.0) / required) : 0;
    }

    // 添加新的方法
    public void addNail() {
        nailTimestamps.add(System.currentTimeMillis());
    }

    public List<Long> getNailTimestamps() {
        return nailTimestamps;
    }

    public void setNailTimestamps(List<Long> nailTimestamps) {
        this.nailTimestamps = nailTimestamps;
    }

    // 获取当前的钉子状态列表
    public List<NailState> getNailStates() {
        List<NailState> states = new ArrayList<>();
        long currentTime = System.currentTimeMillis();
        
        for (Long timestamp : nailTimestamps) {
            long diffHours = (currentTime - timestamp) / (60 * 60 * 1000);  // 改用小时计算
            
            if (diffHours < 24) {  // 24小时内是钉子状态
                states.add(NailState.NAIL);
            } else if (diffHours < 96) {  // 24+72=96小时内是孔洞状态
                states.add(NailState.HOLE);
            }
            // 超过96小时的不添加到状态列表中
        }
        
        return states;
    }

    public enum NailState {
        NAIL,   // 钉子
        HOLE    // 孔洞
    }
}